package com.qianfeng.xinyihezi.xinyihezi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qianfeng.xinyihezi.xinyihezi.R;
import com.qianfeng.xinyihezi.xinyihezi.model.PopcatBean;

import java.util.List;

/**
 * 作者：王加威 on 2016/11/13 17:21
 */

public class MyGridAdapter extends BaseAdapter{
    private Context context;
    private List<PopcatBean> mData;

    public MyGridAdapter(Context context, List<PopcatBean> mData) {
        this.context = context;
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData==null?0:mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView==null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.gridview_item,null);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.tv1.setText(mData.get(position).obj_name);
        viewHolder.tv2.setText(mData.get(position).description);
        Glide.with(context).load(mData.get(position).image_url).into(viewHolder.iv);
        return convertView;
    }
    public static class ViewHolder{
        private TextView tv1,tv2;
        private ImageView iv;
        public ViewHolder(View view){
            tv1= (TextView) view.findViewById(R.id.gridview_item_tv1);
            tv2= (TextView) view.findViewById(R.id.gridview_item_tv2);
            iv= (ImageView) view.findViewById(R.id.gridview_item_iv);
        }
    }
}
